package net.jiastudy.biz.job;

import net.jiastudy.biz.datasync.DataSyncService;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.quartz.QuartzJobBean;

import javax.annotation.Resource;

@DisallowConcurrentExecution
public class DeptAndTeacherSyncTask extends QuartzJobBean {
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Resource
    private DataSyncService dataSyncService;
    @Value("${sync.operate}")
    private Boolean syncOperate;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        if (!this.syncOperate) {
            logger.debug("未开启数据同步，执行结束");
            return;
        }

        logger.debug("开始同步数据");
        dataSyncService.syncAll();
    }
}
